/******************************************************
// Copyright 2008 Derrick Pallas. All rights reserved.
//
// This file is part of c-ptr.
//
// c-ptr is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// c-ptr is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with c-ptr.  If not, see <http://www.gnu.org/licenses/>.
*/

#ifndef C_PTR_H
#define C_PTR_H

#include <cstddef>
#include <cstdlib>
#include <boost/noncopyable.hpp>

#include "basic_ptr.h"

namespace ptr
{
  template< typename T >
    inline void free( T * ptr ) { ::free(ptr); };
  
  template< typename T, void(*F)(T*) = free<T> >
  class c : public ptr::basic<T>, private boost::noncopyable
  {
  public:
    typedef T my_type;
    typedef my_type * ptr_type;
    typedef ptr::basic<my_type> base;

  public:
    explicit c( ptr_type that = NULL ) : base(that) { }
   ~c( ) { if (this->ptr) F(this->ptr); }

    my_type * operator = ( my_type * that ) { return this->ptr=that; }
  };
}

#endif // C_PTR_H
